# Contributor: Liu Pak Hin <wl@m-labs.hk>

_realname=rapidfuzz
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.13.7
pkgrel=1
pkgdesc="Rapid fuzzy string matching. (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('MIT')
url="https://github.com/maxbachmann/RapidFuzz"
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-scikit-build"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('8d3e252d4127c79b4d7c2ae47271636cbaca905c8bb46d80c7930ab906cf4b5c')

prepare(){
  cd "${srcdir}"
  cp -r "RapidFuzz-${pkgver}" "python-build-${MSYSTEM}"
  rm -rf "python-build-${MSYSTEM}/extern"
  cp -r "${_realname}-${pkgver}/extern" "python-build-${MSYSTEM}/extern"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
